﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Esa.UI
{
    public class AudioMgr : Singleton<AudioMgr>
    {
        public float bpm { set { _bpm = value; UpdateBPM(); } get { return _bpm; } }// Beats Per Minute
        public float bps { get { return _bps; } } // beats per second
        public float spb { get { return _spb; } } // seconds per beat
        public float spn { get { return _spn; } } // seconds per note
        public int npb { set { _npb = value; UpdateBPM(); } get { return _npb; } } // 一拍有几个音符 notes Per Beat
        public float _bpm = 120;
        [SerializeField] private float _bps;
        [SerializeField] private float _spb;
        [SerializeField] private float _spn;
        public int _npb = 4;
        public bool updateBPM_pf = true; // Per Frame

        [Button]
        void UpdateBPM()
        {
            SetBPM(_bpm);
        }
        private void Start()
        {
            UpdateBPM();
        }
        private void Update()
        {
            if (updateBPM_pf) UpdateBPM();
        }
        void SetBPM(float bpm)
        {
            _bps = (bpm / 60);
            _spb = 1 / bps;
            _spn = spb / npb;
        }
    }
}